package com.bianxianmao.lastknow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bianxianmao.R;
import com.bianxianmao.lastknow.bean.LastKnowBean;

import java.util.List;

/**
 * Created by Administrator on 2017/8/13.
 */

public class NewAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<LastKnowBean.ReturnValueBean> mData;
    private Context mContext;

    public NewAdapter(Context mContext, List<LastKnowBean.ReturnValueBean> mData) {
        this.mContext = mContext;
        this.mData = mData;
        this.mInflater = LayoutInflater.from(mContext);

    }

    public void setData(List<LastKnowBean.ReturnValueBean> list) {
        this.mData = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData != null ? mData.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mData != null ? mData.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        //绑定控件
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.lastknow_item1, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //绑定数据
//        LastKnowBean.ReturnValueBean returnValueBean = mData.get(position);
//        Glide.with(mContext).load(returnValueBean.getImage1()).into(holder.ivGoods);
//        holder.tvGoodsinfo.setText(returnValueBean.getProductName());
//        float dbSurplusCount = (float)(returnValueBean.getDbSurplusCount());
//        float dbTotalCount = (float)(returnValueBean.getDbTotalCount());
//        float a = (dbSurplusCount/dbTotalCount)*100;
//        holder.pb.setProgress((int) a);
//        holder.tvAll.setText(returnValueBean.getDbTotalCount()+"");
//        holder.tvSurplus.setText(returnValueBean.getDbSurplusCount()+"");
        return convertView;
    }

    class ViewHolder {
        public ImageView ivGoods;
        public TextView tvGoodsinfo;
        public RelativeLayout rlGood;
        public ProgressBar pb;
        public TextView tvAll;
        public TextView tvSurplus;

        public ViewHolder(View itemView) {
            ivGoods = (ImageView) itemView.findViewById(R.id.iv_goods);
            tvGoodsinfo = (TextView) itemView.findViewById(R.id.tv_goodsinfo);
            rlGood = (RelativeLayout) itemView.findViewById(R.id.rl_good);
            pb = (ProgressBar) itemView.findViewById(R.id.pb);
            tvAll = (TextView) itemView.findViewById(R.id.tv_all);
            tvSurplus = (TextView) itemView.findViewById(R.id.tv_surplus);
        }
    }

}
